﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;
using System.Data.SqlClient;

namespace CAD.DAO
{
    public class DAOKardex
    {
        public int Insertar(int LKARDEX_ID, DateTime DTFECHA_DT, string SESTADO, string SDESCRIPCION_DSC, bool BDEVOLUCION_FL, double IVALOR, int ICONCURRENCIA, int LPUNTOS_ID, int LACTIVOS_ID, int LPERSONAL_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LKARDEX_ID ";
            prmA.Direction = ParameterDirection.Output;
            lstParametros.Add(prmA);

            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.DateTime;
            prmB.ParameterName = "@DTFECHA_DT";
            prmB.Value = DTFECHA_DT;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmCq = new SqlParameter();
            prmCq.DbType = DbType.String;
            prmCq.ParameterName = "@SESTADO ";
            prmCq.Value = SESTADO;
            prmCq.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCq);

            DbParameter prmCs = new SqlParameter();
            prmCs.DbType = DbType.String;
            prmCs.ParameterName = "@SDESCRIPCION_DSC";
            prmCs.Value = SDESCRIPCION_DSC;
            prmCs.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCs);
            DbParameter prmxC = new SqlParameter();
            prmxC.DbType = DbType.Int32;
            prmxC.ParameterName = "@IVALOR";
            prmxC.Value = IVALOR;
            prmxC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmxC);
            DbParameter prmsC = new SqlParameter();
            prmsC.DbType = DbType.Boolean;
            prmsC.ParameterName = "@BDEVOLUCION_FL";
            prmsC.Value = BDEVOLUCION_FL;
            prmsC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmsC);



            DbParameter prmcC = new SqlParameter();
            prmcC.DbType = DbType.Int32;
            prmcC.ParameterName = "@ICONCURRENCIA";
            prmcC.Value = 1;
            prmcC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmcC);

            DbParameter prmCz = new SqlParameter();
            prmCz.DbType = DbType.Int32;
            prmCz.ParameterName = "@LPUNTOS_ID";
            prmCz.Value = LPUNTOS_ID;
            prmCz.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCz);

            DbParameter prmCy = new SqlParameter();
            prmCy.DbType = DbType.Int32;
            prmCy.ParameterName = "@LACTIVOS_ID";
            prmCy.Value = LACTIVOS_ID;
            prmCy.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCy);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.Int32;
            prmC.ParameterName = "@LPERSONAL_ID";
            prmC.Value = 1;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmCw = new SqlParameter();
            prmCw.DbType = DbType.Int32;
            prmCw.ParameterName = "@SESTADO ";
            prmCw.Value = 1;
            prmCw.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCw);


            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento ";
            prmD.Value = 1;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            SQLConexion conProxy = new SQLConexion();
            if (conProxy.EjecutarDML(lstParametros, "dbo.SPABM_AREAS"))
                return Convert.ToInt32(prmA.Value);
            return -1;

        }
        public int Insertar(string nombre, int ICONCURRENCIA, SqlTransaction transaccion)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LAREAS_ID";
            prmA.Direction = ParameterDirection.Output;
            lstParametros.Add(prmA);

            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.String;
            prmB.ParameterName = "@SNOMBRE_AREA";
            prmB.Value = nombre;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.Int32;
            prmC.ParameterName = "@ICONCURRENCIA ";
            prmC.Value = 1;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento ";
            prmD.Value = 1;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            if (conProxy.EjecutarDML(lstParametros, "dbo.SPABM_AREAS", transaccion))
                return Convert.ToInt32(prmA.Value);
            return -1;

        }
        public bool Actualizar(int LKARDEX_ID, DateTime DTFECHA_DT, string SESTADO, string SDESCRIPCION_DSC, bool BDEVOLUCION_FL, double IVALOR, int ICONCURRENCIA, int LPUNTOS_ID, int LACTIVOS_ID, int LPERSONAL_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LKARDEX_ID";
            prmA.Value = LKARDEX_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);


            DbParameter prmB = new SqlParameter();
            prmB.DbType = DbType.DateTime;
            prmB.ParameterName = "@DTFECHA_DT";
            prmB.Value = DTFECHA_DT;
            prmB.Direction = ParameterDirection.Input;
            lstParametros.Add(prmB);

            DbParameter prmCq = new SqlParameter();
            prmCq.DbType = DbType.String;
            prmCq.ParameterName = "@SESTADO ";
            prmCq.Value = SESTADO;
            prmCq.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCq);

            DbParameter prmCs = new SqlParameter();
            prmCs.DbType = DbType.String;
            prmCs.ParameterName = "@SDESCRIPCION_DSC";
            prmCs.Value = SDESCRIPCION_DSC;
            prmCs.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCs);

            DbParameter prmsC = new SqlParameter();
            prmsC.DbType = DbType.String;
            prmsC.ParameterName = "@BDEVOLUCION_FL";
            prmsC.Value = BDEVOLUCION_FL;
            prmsC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmsC);

            DbParameter prmxC = new SqlParameter();
            prmxC.DbType = DbType.Int32;
            prmxC.ParameterName = "@IVALOR";
            prmxC.Value = IVALOR;
            prmxC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmxC);

            DbParameter prmcC = new SqlParameter();
            prmcC.DbType = DbType.Int32;
            prmcC.ParameterName = "@ICONCURRENCIA";
            prmcC.Value = 1;
            prmcC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmcC);

            DbParameter prmCz = new SqlParameter();
            prmCz.DbType = DbType.Int32;
            prmCz.ParameterName = "@LPUNTOS_ID";
            prmCz.Value = LPUNTOS_ID;
            prmCz.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCz);

            DbParameter prmCy = new SqlParameter();
            prmCy.DbType = DbType.Int32;
            prmCy.ParameterName = "@LACTIVOS_ID";
            prmCy.Value = LACTIVOS_ID;
            prmCy.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCy);

            DbParameter prmC = new SqlParameter();
            prmC.DbType = DbType.Int32;
            prmC.ParameterName = "@LPERSONAL_ID";
            prmC.Value = 1;
            prmC.Direction = ParameterDirection.Input;
            lstParametros.Add(prmC);

            DbParameter prmCw = new SqlParameter();
            prmCw.DbType = DbType.Int32;
            prmCw.ParameterName = "@SESTADO ";
            prmCw.Value = 2;
            prmCw.Direction = ParameterDirection.Input;
            lstParametros.Add(prmCw);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarDML(lstParametros, "dbo.SPABM_AREAS");
        }
        public bool Eliminar(int LKARDEX_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LKARDEX_ID";
            prmA.Value = LKARDEX_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento ";
            prmD.Value = 3;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);

            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarDML(lstParametros, "dbo.SPABM_AREAS");
        }
        public DataSet Traer()
        {
            List<DbParameter> lstParametros = new List<DbParameter>();
            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 4;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_AREAS");
        }
        public DataSet TraerXId(int LKARDEX_ID)
        {
            List<DbParameter> lstParametros = new List<DbParameter>();

            DbParameter prmA = new SqlParameter();
            prmA.DbType = DbType.Int32;
            prmA.ParameterName = "@LKARDEX_ID";
            prmA.Value = LKARDEX_ID;
            prmA.Direction = ParameterDirection.Input;
            lstParametros.Add(prmA);

            DbParameter prmD = new SqlParameter();
            prmD.DbType = DbType.Int32;
            prmD.ParameterName = "@iEvento";
            prmD.Value = 5;
            prmD.Direction = ParameterDirection.Input;
            lstParametros.Add(prmD);
            SQLConexion conProxy = new SQLConexion();
            return conProxy.EjecutarConsulta(lstParametros, "dbo.SPABM_AREAS");
        }

    }
}
